<?php

namespace App\Models\DylistModels;
use App\Models\ParentModel;
use ClassesWithParents\D;
use DB;
use App\Components\Tools;
use Log;
/**
 * 抖音体育榜model
 * @author puppet
 */
class DySport extends ParentModel
{
    /**
     * 与模型关联的数据表。
     *
     * @var string
     */
    protected $table = 'pt_dy_sport_overall';

    /**
     * DB::直接操作的数据库表名
     * @var string
     */
    protected $db_table = 'pt_dy_sport_overall';

    /**
     * 主键 默认id。
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 指定是否模型应该被戳记时间。
     *
     * @var bool
     */
    public $timestamps = false;


    /**
     *    ajax 拉取数据 type 1总榜 2xx榜 怎么查暂时没考虑好
     */
    function getPageData(){
        $limit=50;
        $sql=" select * from $this->table where type=1 ";
        $sql.=" order by effect_value desc limit $limit";
    }

    //插入体育榜数据
    function upDySportto($date){
        set_time_limit(0);
        foreach ($date as $k => $v) {
            $data = array(
                'rank' => $v['rank'],
                'rank_change' => $v['rank_change'],
                'nickname' =>$v['nickname'],
                'avatar' => $v['avatar'],
                'follower_count' => $v['follower_count'],
                'onbillbaord_times' => $v['onbillbaord_times'],
                'create_time' => date('Y-m-d H:i:s', time()),
                'update_time' => date('Y-m-d H:i:s', time()),
                'type' =>1,
                'effect_value' => $v['effect_value'],
            );
            $bid=DB::table($this->table)->insertGetId($data);
          //  echo ''; print_r($bid);
            $vurl=$v['video_list'];
            if(is_array($vurl)){
                foreach ($vurl as $vk=>$vv){
                    $vdata=array(
                        'item_cover' => $vv['item_cover'],
                        'share_url' => $vv['share_url'],
                        'title' => $vv['title'],
                        'bid' => $bid,
                        'create_time' => date('Y-m-d H:i:s', time()),
                        'update_time' => date('Y-m-d H:i:s', time()),
                        'type' =>2,
                    );
                    DB::table("pt_dy_bangdan_video")->insertGetId($vdata);//把榜单视频数据按昵称存入库
                }
            }

        }
    }

}